<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title></title>
</head>

<body>
<script type="text/javascript">
function Gen(time) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            if (time < 500) {
                resolve(time)
            } else {
                reject(time)
            }
        }, time)
    })
}
Gen(Math.random()*1000)
    .then(val => console.log('resolve',val))
    .catch(err => console.log('err',err))
    .finally(()=>{console.log('finnish')})

</script>
</body>

</html>